import {message} from 'antd';
import {history} from '@umijs/max';
import request from '@/utils/request';

const userModel = {
  namespace: 'user',
  state: {
    userList: [],
  },
  effects: {
    *init(_, {call, put}){
      const data = yield call(() => request('/api2/games/getGames'));
    },
    *fakeLogin({payload},{call}){
      yield call(() => request('/api2/auth/login', {method: 'post', data: {userName: payload?.username, passWord: payload?.password}})); // 仅仅为了方便查看控制台数据
    },
    *upData({payload}, {call, put}){
      const {data = {}, code} = yield call(() => request('/api2/auth/upData', {method: 'post', data: {...payload}}));
      if (code && code === 200 && data?.userId){
        message.success('修改成功');
        setTimeout(() => {
          location.reload();
        }, 300)
      }
    }
  },
};
export default userModel;
